home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / Net::netent.Z / Net::netent
Encoding:
Text File  |  1998-10-28  |  5.0 KB  |  199 lines

  1.  
  2.  
  3.  
  4.      NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))  22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))    NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       Net::netent -    by-name    interface to Perl's built-in getnet*()
  10.       functions
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.        use Net::netent qw(:FIELDS);
  14.        getnetbyname("loopback")          or die "bad net";
  15.        printf "%s is %08X\n", $n_name, $n_net;
  16.  
  17.        use Net::netent;
  18.  
  19.        $n =    getnetbyname("loopback")      or die "bad net";
  20.        { # there's gotta be    a better way, eh?
  21.            @bytes =    unpack("C4", pack("N", $n->net));
  22.            shift @bytes while @bytes && $bytes[0] == 0;
  23.        }
  24.        printf "%s is %08X [%d.%d.%d.%d]\n",    $n->name, $n->net, @bytes;
  25.  
  26.  
  27.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  28.       This module's    default    exports    override the core
  29.       _g_e_t_n_e_t_b_y_n_a_m_e() and _g_e_t_n_e_t_b_y_a_d_d_r() functions, replacing them
  30.       with versions    that return "Net::netent" objects.  This
  31.       object has methods that return the similarly named structure
  32.       field    name from the C's netent structure from    _n_e_t_d_b._h;
  33.       namely name, aliases,    addrtype, and net.  The    aliases    method
  34.       returns an array reference, the rest scalars.
  35.  
  36.       You may also import all the structure    fields directly    into
  37.       your namespace as regular variables using the    :FIELDS    import
  38.       tag.    (Note that this    still overrides    your core functions.)
  39.       Access these fields as variables named with a    preceding n_.
  40.       Thus,    $net_obj->name() corresponds to    $n_name    if you import
  41.       the fields.  Array references    are available as regular array
  42.       variables, so    for example @{ $net_obj->aliases() } would be
  43.       simply @n_aliases.
  44.  
  45.       The _g_e_t_n_e_t() funtion is a simple front-end that forwards a
  46.       numeric argument to _g_e_t_n_e_t_b_y_a_d_d_r(), and the rest to
  47.       _g_e_t_n_e_t_b_y_n_a_m_e().
  48.  
  49.       To access this functionality without the core    overrides,
  50.       pass the use an empty    import list, and then access function
  51.       functions with their full qualified names.  On the other
  52.       hand,    the built-ins are still    available via the CORE::
  53.       pseudo-package.
  54.  
  55.      EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  56.       The _g_e_t_n_e_t() functions do this in the    Perl core:
  57.  
  58.           sv_setiv(sv, (I32)nent->n_net);
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))  22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))    NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))
  71.  
  72.  
  73.  
  74.       The _g_e_t_h_o_s_t()    functions do this in the Perl core:
  75.  
  76.           sv_setpvn(sv, hent->h_addr, len);
  77.  
  78.       That means that the address comes back in binary for the
  79.       host functions, and as a regular perl    integer    for the    net
  80.       ones.     This seems a bug, but here's how to deal with it:
  81.  
  82.        use strict;
  83.        use Socket;
  84.        use Net::netent;
  85.  
  86.        @ARGV = ('loopback')    unless @ARGV;
  87.  
  88.        my($n, $net);
  89.  
  90.        for $net ( @ARGV ) {
  91.  
  92.            unless ($n = getnetbyname($net))    {
  93.           warn "$0: no such net: $net\n";
  94.           next;
  95.            }
  96.  
  97.            printf "\n%s is %s%s\n",
  98.               $net,
  99.               lc($n->name) eq lc($net) ? "" : "*really*    ",
  100.               $n->name;
  101.  
  102.            print "\taliases    are ", join(", ", @{$n->aliases}), "\n"
  103.               if @{$n->aliases};
  104.  
  105.            # this is stupid; first,    why is this not    in binary?
  106.            # second, why am    i going    through    these convolutions
  107.            # to make it looks right
  108.            {
  109.           my @a    = unpack("C4", pack("N", $n->net));
  110.           shift    @a while @a && $a[0] ==    0;
  111.           printf "\taddr is %s [%d.%d.%d.%d]\n", $n->net, @a;
  112.            }
  113.  
  114.            if ($n =    getnetbyaddr($n->net)) {
  115.           if (lc($n->name) ne lc($net))    {
  116.               printf "\tThat addr reverses to net %s!\n", $n->name;
  117.               $net = $n->name;
  118.               redo;
  119.           }
  120.            }
  121.        }
  122.  
  123.  
  124.      NNNNOOOOTTTTEEEE
  125.       While    this class is currently    implemented using the
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))  22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))    NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))
  137.  
  138.  
  139.  
  140.       Class::Struct    module to build    a struct-like class, you
  141.       shouldn't rely upon this.
  142.  
  143.      AAAAUUUUTTTTHHHHOOOORRRR
  144.       Tom Christiansen
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.